
import { prod, storeup, addBuycar } from '@/services'


const state = {
    prodlist: {},
    creatIndex:0
}
// “getters:类似是Vuex中的计算属性,也具有缓存功能:
// 如果state中的数据得到了改变,那么getters中的属性的值也会发生改变,
// 如果state的值没有发生任何变化,那么getters中的属性,的值就不会发生改变”
const getters = {};


const mutations = {
    get_prodobj(state, payload) {
        state.prodlist = {...payload.prodlist,isCollection:false}
    },
    get_storeup(state, payload) {     
        state.prodlist = {...state.prodlist,isCollection:!state.prodlist.isCollection}
    }
    
}

const actions = {
    async prodobj({ commit }, payload) {
        let result = await prod(payload)
        if (result) {
            commit('get_prodobj', { prodlist: result })
        }
    },

    async storeup({ commit }, payload) {
            await storeup(payload);            
            commit('get_storeup', { storeupobj: payload })
    },
    // 加入购物车
    async addBuycar({commit},payload){
        let result = await addBuycar(payload);
        console.log(result,'result.......')
        if(!result){
            uni.showToast({
                title: '加入购物车成功',
                icon:'none',
                duration: 850
              });
        }
       
        
    }       
    
}


export default {
    namespaced: true,
    modules: {},
    state, getters, mutations, actions
}